package com.singzi.leetcode.N300;

public class T0021 {
    public static void main(String[] args) {
        char[][] matrix = {{'0','1'}};
        Solution0021 solution0021 = new Solution0021();
        System.out.println(solution0021.maximalSquare(matrix));
    }
}
class Solution0021 {
    public int maximalSquare(char[][] matrix) {
        int area = 0;
        int m = matrix.length;
        int n = matrix.length;
        for(int i = 0;i < m;i++){
            for(int j = 0;j < n;j++){
                if(matrix[i][j] == '1'){
                    int cont = 1;
                    int k = Math.min(m - i, n - j);
                    flag:for(int index = 1;index < k;index++){
                        for(int row = j;row <= j+k;row++){
                            if(matrix[i+index][row] == '0') break flag;
                        }
                        for(int col = i;col <= i+k;col++){
                            if(matrix[col][j+index] == '0') break flag;
                        }
                        cont++;
                    }
                    area = Math.max(cont, area);
                }
            }
        }


        return area*area;
    }
}